#include"ringbuffer.hpp"
#include<pthread.h>
#include<unistd.h>
#include<ctime>
#include<functional>



using namespace RingBufferModule;

void* Consumer(void* args)
{
	RingBuffer<int> *rq = static_cast<RingBuffer<int>*>(args);
	int data;
	while(1)
	{
		sleep(1);
		rq->Pop(&data);
		std::cout << "消费了一个数据 " << data << std::endl;
	}
}

void* Productor(void* args)
{
	RingBuffer<int> *rq = static_cast<RingBuffer<int>*>(args);

	int data = 10;
	while(1)
	{
		rq->Equeue(data);
		data++;
		std::cout << "生产了一个数据" << data << std::endl;
	}
}


int main()
{
	RingBuffer<int> *rq  = new RingBuffer<int>(5);

	// 单生产 单消费
	pthread_t c1,c2,c3,p1,p2;

	pthread_create(&c1,nullptr,Consumer,rq);
	pthread_create(&c2,nullptr,Consumer,rq);
	pthread_create(&c3,nullptr,Consumer,rq);
	pthread_create(&p1,nullptr,Productor,rq); 
	pthread_create(&p2,nullptr,Productor,rq); 


	pthread_join(c1,nullptr);
	pthread_join(c2,nullptr);
	pthread_join(c3,nullptr);
	pthread_join(p1,nullptr);
	pthread_join(p2,nullptr);

	delete rq;
}

